package com.ruoyi.visitor.util;
import com.aliyun.tea.*;
/**
 * packageName com.ruoyi.visitor.util
 *
 * @author wfx
 * @version JDK 8
 * @className Sample
 * @date 2025/4/25
 * @description TODO
 */


public class Sample {

    public static void main(String[] args) throws Exception {
        System.setProperty("ALIBABA_CLOUD_ACCESS_KEY_ID","LTAI5tLFx8SXDxcpL5TvfL5j");
        System.setProperty("ALIBABA_CLOUD_ACCESS_KEY_SECRET","XLlLeNLsLA3rPPgH43khNzexfZCG73");
        try {
            // 构建request。
            com.aliyun.cloudauth20190307.models.Id2MetaVerifyRequest request = new com.aliyun.cloudauth20190307.models.Id2MetaVerifyRequest();
            request.paramType = "normal";
            request.userName = "位峰祥";
            request.identifyNum = "37028319841005221X";
            // 自动路由服务。
            com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse response = Sample.id2MetaVerifyAutoRoute(request);
            String ret = com.aliyun.teautil.Common.toJSONString(com.aliyun.teautil.Common.toMap(response));
            com.aliyun.teaconsole.Client.log("最终结果（若此处为空，则所有服务点均异常，请逐步调试）：" + ret + "");
        } catch (TeaException error) {
            com.aliyun.teaconsole.Client.error(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            com.aliyun.teaconsole.Client.error(error.message);
        }
    }

    /**
     * <b>description</b> :
     * <p>主备服务点循环调用，获取到成功结果返回。</p>
     */
    public static com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse id2MetaVerifyAutoRoute(com.aliyun.cloudauth20190307.models.Id2MetaVerifyRequest request) throws Exception {
        java.util.List<String> endpoints = java.util.Arrays.asList(
                "cloudauth.cn-shanghai.aliyuncs.com",
                "cloudauth.cn-beijing.aliyuncs.com"
        );
        com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse lastResponse = null;
        for (String endpoint : endpoints) {
            try {
                // 调用服务。
                com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse response = Sample.id2MetaVerify(endpoint, request);
                // 节点调用结果
                String ret = com.aliyun.teautil.Common.toJSONString(com.aliyun.teautil.Common.toMap(response));
                com.aliyun.teaconsole.Client.log("节点 " + endpoint + " 结果：" + ret + " ");
                // 有一个服务调用成功即返回。
                if (!com.aliyun.teautil.Common.isUnset(response) && com.aliyun.teautil.Common.equalNumber(response.statusCode, 200)) {
                    if (!com.aliyun.teautil.Common.isUnset(response.body) && com.aliyun.teautil.Common.equalString(response.body.code, "200")) {
                        lastResponse = response;
                        break;
                    }

                }

            } catch (TeaException error) {
                com.aliyun.teaconsole.Client.error("节点 " + endpoint + " 调用异常：" + error.message + "");
            } catch (Exception _error) {
                TeaException error = new TeaException(_error.getMessage(), _error);
                com.aliyun.teaconsole.Client.error("节点 " + endpoint + " 调用异常：" + error.message + "");
            }
        }
        return lastResponse;
    }

    /**
     * <b>description</b> :
     * <p>获取服务Client实例，调用验证方法。</p>
     */
    public static com.aliyun.cloudauth20190307.models.Id2MetaVerifyResponse id2MetaVerify(String endpoint, com.aliyun.cloudauth20190307.models.Id2MetaVerifyRequest request) throws Exception {
        // 获取SDK Client实例。
        com.aliyun.cloudauth20190307.Client client = Sample.createClient(endpoint);
        // 构建RuntimeObject
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        runtime.readTimeout = 5000;
        runtime.connectTimeout = 5000;
        // 连接
        return client.id2MetaVerifyWithOptions(request, runtime);
    }

    /**
     * <b>description</b> :
     * <p>安全创建服务Client实例。</p>
     */
    public static com.aliyun.cloudauth20190307.Client createClient(String endpoint) throws Exception {
        // 获取Credential工具，此工具会从环境变量中读取AccessKey。
        com.aliyun.credentials.models.Config credentialConfig = new com.aliyun.credentials.models.Config();
        com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client(credentialConfig);
        // 创建SDK Client实例。
        com.aliyun.teaopenapi.models.Config apiConfig = new com.aliyun.teaopenapi.models.Config();
        apiConfig.credential = credential;
        apiConfig.endpoint = endpoint;
        return new com.aliyun.cloudauth20190307.Client(apiConfig);
    }
}
